<?php
	require_once('useraccesscontrol.class.php');
	require_once('configdatabase.class.php');
	require_once('databaseevent.class.php');
	require_once('databaseeventlist.class.php');
	
	$userAccessControl = new UserAccessControl();
	$userAccessControl->grantAccessOnlyForMods();
	
	$message = null;
	$database = new ConfigDatabase();
	if (isset($_POST['approveeventsubmit'])) {
		$event = new DatabaseEvent($_POST['id'], null, null);
		$event->approve($database->getConnection());
		$message = 'Event wurde freigegeben.';
	}
	$eventList = new DatabaseEventList();
	$eventList->read($database->getConnection(), true, true, true);
	$numberOfEvents = $eventList->count();
?>
<html>
	<head>
		<title>Event freigeben</title>
		<link rel="stylesheet" type="text/css" href="style.css">
	</head>
	<body>
		<h1>Event freigeben</h1>
		<?php if (null !== $message): ?>
			<p class="message"><?php echo($message); ?></p>
		<?php endif; ?>
		<form action="approveevent.php" method="post">
			<table class="eventtable" style="margin-bottom:15px">
				<?php foreach ($eventList as $event): ?>
					<tr>
						<td style="width:20px"><input type="radio" name="id" value="<?php echo($event->getId()); ?>" /></td>
						<td class="date"><?php echo($event->getDateTime()->format('d.m.Y')); ?></td>
						<td><?php echo(htmlentities($event->getTitle())); ?></td>
					</tr>
				<?php endforeach; ?>
			</table>
			<input type="submit" name="approveeventsubmit" value="Freigeben" />
		</form>
		<div id="bottomlinks">
			<a href="modmenu.php">Modmen&uuml;</a>
			<br style="clear: both;" />
		</div>
	</body>
</html>